package util.AST.Comando.Simples;

import java.util.ArrayList;

import util.AST.Expressao.Expressao;
import util.AST.Comando.Simples.ComandoSimples;;

public class ComandoIf extends ComandoSimples {

	private Expressao condicao;
	private ArrayList<ComandoSimples> comandosIf;
	private ArrayList<ComandoSimples> comandosElse;
	
	public ComandoIf(Expressao condicao, ArrayList<ComandoSimples> comandosIf, ArrayList<ComandoSimples> comandosElse) {
		this.condicao = condicao;
		this.comandosIf = comandosIf;
		this.comandosElse = comandosElse;
	}

	@Override
	public String toString(int level) {
		int nextLevel = level+5;
		StringBuffer str = new StringBuffer();
		str.append("IFEL\n");
		str.append(super.getSpaces(nextLevel) + "|-COND\n");
		str.append(super.getSpaces(nextLevel+5) + "|-");
		if ( this.condicao != null ) {
			str.append(this.condicao.toString(nextLevel+5));
		}
		str.append(super.getSpaces(nextLevel) + "|-IFEL\n");
		if ( this.comandosIf != null ) {
			for (ComandoSimples statement : this.comandosIf) {
				str.append(super.getSpaces(nextLevel+5) + "|-");			
				str.append(statement.toString(nextLevel+5));
			}
		}
		str.append(super.getSpaces(nextLevel) + "|-ELSE\n");
		if ( this.comandosElse != null ) {
			for (ComandoSimples statement : this.comandosElse) {
				str.append(super.getSpaces(nextLevel+5) + "|-");	
				str.append(statement.toString(nextLevel+5));
			}
		}
		return str.toString();
	}

	//get e set
	public Expressao getCondicao() {
		return condicao;
	}

	public void setCondicao(Expressao condicao) {
		this.condicao = condicao;
	}

	public ArrayList<ComandoSimples> getComandosIf() {
		return comandosIf;
	}

	public void setComandosIf(ArrayList<ComandoSimples> comandosIf) {
		this.comandosIf = comandosIf;
	}

	public ArrayList<ComandoSimples> getComandosElse() {
		return comandosElse;
	}

	public void setComandosElse(ArrayList<ComandoSimples> comandosElse) {
		this.comandosElse = comandosElse;
	}
	
	


}
